package com.zsj.hello.Second;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.zsj.hello.util.RabbimqFactoryUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author https://gitee.com/zhengshengjun
 * @date 2023/8/29.
 * <p>
 * 其中
 */
public class Consumer02 {

    public static final String QUEUE_NAME = "hello";
    public static int count = 0;


    public static void main(String[] args) throws IOException, TimeoutException {

        //消息接收的方法
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("2号" + message + "  "+String.valueOf(++count));
        };

        CancelCallback cancelCallback = (comsumerTag) -> {
            System.out.println("消息被中断");
        };

        Channel rabbitMQChannel = RabbimqFactoryUtil.getRabbitMQChannel();

        //消息的接收
        rabbitMQChannel.basicConsume(QUEUE_NAME, true, deliverCallback, cancelCallback);
    }
}
